<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>注册</title>
		<link rel="stylesheet" type="text/css" href="../css/public.css"/>
		<link rel="stylesheet" type="text/css" href="../css/login.css"/>
	</head>
	<body>
		<!-------------------reg-------------------------->
		<div class="reg">
			<form action="#" method="post">
				<h1><a href="index.html"><img src="../img/temp/logo1.jpg"></a></h1>
				<p>用户注册</p>
				<p><input type="text" class="txt_phone" placeholder="输入手机号码"></p>
				<li class="register_li">
					<!--<input type="button" name="" id="verification_code" value="获取验证码"/>-->
					<div id="verification_code">获取验证码</div>
					<!--<div class="verification_shade"></div>-->
				</li>
				<p><input type="text" class="verification_code" placeholder="输入验证码信息"></p>
				<p><input type="text" class="padwd" placeholder="输入密码"></p>
				<!--<p class="txtL txt"><input class="code" type="text" name="" value="" placeholder="验证码"><img src="../img/temp/code.jpg"></p>-->
				<!--<p id="register_login"><input type="submit" value="注册"></p>-->
				<p id="register_login">注册</p>
				<p class="txtL txt">完成此注册，即表明您同意了我们的<a href="#"><使用条款和隐私策略></a></p>
				<p class="active_area">已有账号登录</p>
				<!--<a href="#" class="off"><img src="img/temp/off.png"></a>-->
			</form>
		</div>
		<div class="dialog_box">
			<p>温馨提示</p>
			<span></span>
			<div class="close_dialog" type="button">确定</div>
		</div>
	</body>

	<script src="../js/jquery-1.11.1.min.js?time=2017072509"></script>
	<script src="../js/all.js?time=20170801"></script>
	<script>
        $(function() {
            $(".active_area").click(function() {
                window.location.href = 'login.html';
            });
            $(".txt_phone,.verification_code,.padwd").focus(function() {
                shouCler(this);
            });

            function shouCler(obj) {
                $('.clear').hide();
                $(obj).parent().siblings(".clear").show();
            }

            $(".clear").click(function() {
                var th = $(this).siblings().children().val('');
            });

            var countdown = 60;

            function settime() {
                if(countdown == 0) {
                    $("#verification_code").html('获取验证码').css("background", "rgb(232,91,91)").css("color", '#fff').css("z-index", '1');
                } else {
                    $("#verification_code").html('重新发送(' + countdown + ')').css("background", "#000").css("color", 'darkgrey').css("z-index", '-1');
                    countdown--;
                }
                setTimeout(function() {
                    settime();
                }, 1000)
            }
            //发送验证码
            $(".register_li").click(function() {
                $("#verification_code").css("background-color", '#901C1C').css('color','#988E8E');
                setTimeout(function() {
                    $("#verification_code").css("background-color", 'rgb(232,91,91)').css('color','#fff');
                }, 300);
                $(".clear").hide();
                var txt_phone = $(".txt_phone").val();
                $.ajax({
                    type: "post",
                    url: host + "/api/message/verifycode/get",
                    data: {
                        PhoneNumber: txt_phone,
                        VerifyCodeType: 0
                    },
                    success: function(data) {
                        if(data.ResultType == 3) {
                            settime();
                            showDiag("验证码已发送");
                        } else {
                            showDiag(data.Message);
                        }
                    }
                });
            });

            //登陆
            $("#register_login").click(function() {
                // showDiag("请输入手机号码");
                var txt_phone = $(".txt_phone").val();
                var verification_code = $(".verification_code").val();
                var padwd = $(".padwd").val();
                // console.log('1111')

                $.ajax({
                    type: "post",
                    url: host + "/api/members/member/register",
                    data: {
                        PhoneNumber: txt_phone,
                        VerifyCode: verification_code,
                        PassWord: padwd
                    },
                    success: function(data) {
                        if(data.ResultType == 3) {
                            $.ajax({
                                type: "post",
                                url: host + '/api/members/member/login',
                                data: {
                                    PhoneNumber: txt_phone,
                                    PassWord: padwd
                                },
                                success: function(data) {
                                    if(data.ResultType == 3) {
                                        localStorage.MemberId = data.Data.MemberId;
                                        localStorage.u_num = data.Data.U_Num;
                                        window.location.href = 'index.html';
                                    } else {
                                        showDiag(data.Message);
                                        // alert('lalalaal'+ data.Message)
                                    }
                                }
                            });
                        } else {
                            showDiag(data.Message);
                            // alert('dangdang'+ data.Message)
                        }
                    }
                });
            });
        });
	</script>

</html>
